﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ColorSweet : MonoBehaviour {
    public enum ColorType {
        Yellow,Purple,Red,Blue,Green,Pink,Any,Count
    }
    public Dictionary<ColorType, Sprite> colorSprite;
    [System.Serializable]
    public struct ColorSprite {
        public ColorType type;
        public Sprite Sprite;
    }
    public ColorSprite[] sprites;
    public Image image;
    //颜色种类
    public int NumberColors {
        get { return colorSprite.Count; }
    }

    private ColorType type;
    public ColorType Type {
        get { return type; }
        set { SetColor(value);}
    }
    void Awake() {
        colorSprite = new Dictionary<ColorType, Sprite>();
        image = GetComponent<Image>();
        foreach (var sp in sprites) {
            if (!colorSprite.ContainsKey(sp.type)) {
                colorSprite.Add(sp.type, sp.Sprite);
            }
        }
    }
    void Start() {

    }
    void Update() {

    }

    public void SetColor(ColorType newColor) {
        type = newColor;
        if (colorSprite.ContainsKey(newColor)) {
            image.sprite = colorSprite[newColor];//设置颜色
        }
    }
}
